<?php
/**
 * DouPHP小程序模块
 * Author: cuihaifeng  qq 366131726 微信同号
 * 网址：www.zbxingke.com www.0533hf.com
 */

$smarty->assign('ur_here', $_LANG['wxapp_style']);

//获取样式的操作项

$sql = "SELECT * FROM " . $GLOBALS['dou']->table('config') . " WHERE tab = 'wxapp_s' ORDER BY sort ASC";
$query = $GLOBALS['dou']->query($sql);

$cfg_list = array();
while ($row = $GLOBALS['dou']->fetch_array($query)) {
    $cfg_list[$row['name']] = $row['value'];
}

$smarty->assign('cfg',$cfg_list);

// act操作项的初始化
$act = $check->is_rec($_REQUEST['act']) ? $_REQUEST['act'] : 'default';

// 系统设置
if ($act == 'default') {
    // CSRF防御令牌生成
    $smarty->assign('token', $firewall->get_token());
    $smarty->display('wxapp.htm');
} // 系统设置数据更新
elseif ($act == 'update') {


    if (!file_exists(ROOT_PATH . 'images/wxapp/')) {
        mkdir(ROOT_PATH . 'images/wxapp/', 0777);
    }


    /**
     * banner
     */
    if ($_FILES['wxapp_header_banner']['name'] != '') {
        $logo_dir = ROOT_PATH . 'images/wxapp/'; // logo上传路径,结尾加斜杠
        $logo = new Upload($logo_dir, ''); // 实例化类文件
        $upfile = $logo->upload_image('wxapp_header_banner', 'banner'); // 上传的文件域
        $_POST['wxapp_header_banner'] = 'images/wxapp/' . $upfile;
    }

    if ($_FILES['wxapp_video_banner']['name'] != '') {
        $logo_dir = ROOT_PATH . 'images/wxapp/'; // logo上传路径,结尾加斜杠
        $logo = new Upload($logo_dir, ''); // 实例化类文件
        $upfile = $logo->upload_image('wxapp_video_banner', 'video_banner'); // 上传的文件域
        $_POST['wxapp_video_banner'] = 'images/wxapp/' . $upfile;
    }

    if ($_FILES['wxapp_service_banner']['name'] != '') {
        $logo_dir = ROOT_PATH . 'images/wxapp/'; // logo上传路径,结尾加斜杠
        $logo = new Upload($logo_dir, ''); // 实例化类文件
        $upfile = $logo->upload_image('wxapp_service_banner', 'service_banner'); // 上传的文件域
        $_POST['wxapp_service_banner'] = 'images/wxapp/' . $upfile;
    }





    // CSRF防御令牌验证
    $firewall->check_token($_POST['token']);

    foreach ($_POST as $name => $value) {
        if (is_array($value)) $value = serialize($value);
        $dou->query("UPDATE " . $dou->table('config') . " SET value = '$value' WHERE name = '$name'");
    }
    $dou->create_admin_log($_LANG['wxapp'] . ' - ' . $_LANG['wxapp_system'] . ': ' . $_LANG['edit_succes']);
    $dou->dou_msg($_LANG['edit_succes'], 'wxapp.php?rec=style');
}


